package com.he.producer;

import com.he.constant.RabbitmqConstant;
import com.he.domain.dto.MailDTO;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author He
 * @version 1.0
 * @Date 2023/9/9 15:40
 * @Desc 邮件生产者
 */
@Component
public class EmailProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送简单邮件
     * @param mailDTO 邮件信息
     */
    public void sendSimpleEmailMessage(MailDTO mailDTO){
        rabbitTemplate.convertAndSend(RabbitmqConstant.EMAIL_EXCHANGE,RabbitmqConstant.EMAIL_SIMPLE_KEY,mailDTO);
    }

    /**
     * 发送HTML邮件
     * @param mailDTO 邮件信息
     */
    public void sendHtmlEmailMessage(MailDTO mailDTO) {
        rabbitTemplate.convertAndSend(RabbitmqConstant.EMAIL_EXCHANGE, RabbitmqConstant.EMAIL_HTML_KEY, mailDTO);
    }
}
